package code1.binary_tree;

import java.util.*;

/**
 * 原题链接：https://leetcode.cn/problems/validate-binary-search-tree/
 */
public class P98 {

    //验证二叉树搜索树

    private List<Integer> list=new ArrayList<>();

    //把树变成数组，中序遍历
    public void buildArray(TreeNode root){
        if(root==null){
            return;
        }
        buildArray(root.left);
        list.add(root.val);
        buildArray(root.right);
    }

    //递归
    public boolean isValidBST(TreeNode root) {
        buildArray(root);
        //校验数组是否单调递增
        for(int i=0;i<list.size()-1;i++){
            if(list.get(i) >= list.get(i+1)){
                return false;
            }
        }
        return true;
    }

}
